package org.ools.nools;


public class StringUtils {

	public static String capitalizeFirstLetter(String name) {
		if (name == null || name.length() == 0) return name;
		String firstLetter = getFirstLetter(name);
		return name.replaceFirst(firstLetter, firstLetter.toUpperCase());
	}

	public static String lowerFirstLetter(String name) {
		if (name == null || name.length() == 0) return name;
		String firstLetter = getFirstLetter(name);
		return name.replaceFirst(firstLetter, firstLetter.toLowerCase());
	}
	
	public static String getFirstLetter(String text) {
		int indexFirstLetter = indexFirstLetter(text);
		return String.valueOf(text.charAt(indexFirstLetter));
	}
	public static int indexFirstLetter(String text) {
		return MatcherUtils.getFirstMatcher("\\p{L}", text).start();
	}
	
	public static String capitalizeFirstLetterOfEachWord(String name) {
		if (name == null || name.isEmpty()) return name;
		
		String[] spaceSplitted = name.split(" ");

		String capitalizedValue = "";
		for (String word : spaceSplitted) {
			capitalizedValue += " "+capitalizeFirstLetter(word);
		}
		return capitalizedValue.replace(" ", "");
	}
}